package com.jy.rhin.facade.infra.controller.audit;


import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.domain.audit.AuditInfoDomainService;
import com.jy.rhin.domain.registration.InfraValueSetService;
import com.jy.rhin.facade.infra.controller.audit.assembler.AuditInfoAssembler;
import com.jy.rhin.infra.repo.audit.query.AuditInfoQueryHandler;
import com.jy.rhin.sdk.dto.audit.AuditDto;
import com.jy.rhin.sdk.dto.audit.AuditInfoReqDto;
import com.jy.rhin.sdk.dto.audit.AuditInfoRespDto;
import com.jy.rhin.sdk.dto.audit.AuditWrapperDto;
import com.jy.rhin.sdk.feign.client.AuditFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 审计信息查询服务
 *
 * @author WeiQ
 * @Date 2022年5月17日 13:50:56
 */
@RestController
@RequestMapping("/infra/audit")
@Api(tags = "安全审计服务")
@Slf4j
public class AuditInfoController implements AuditFeign {

    @Resource
    AuditInfoDomainService auditInfoDomainService;
    @Resource
    InfraValueSetService infraValueSetService;
    @Resource
    AuditInfoQueryHandler auditInfoQueryHandler;

    @ApiOperation("添加审计记录")
    @PostMapping("/save")
    @Override
    public Result<Long> save(@RequestBody AuditWrapperDto dto) {
        Long id = auditInfoDomainService.save(AuditInfoAssembler.toDO(dto), infraValueSetService.checkValueField(dto));
        return Result.success(id);
    }

    @ApiOperation("分页查询审计记录")
    @GetMapping("/listAuditInfo")
    @Override
    public Result<Page<AuditInfoRespDto>> listAuditInfo(AuditInfoReqDto dto) {
        return Result.success(auditInfoQueryHandler.selectByPage(dto));
    }

    @ApiOperation("获取审计记录")
    @GetMapping("/getAuditInfo")
    @Override
    public Result<AuditDto> getAuditInfo(Long id) {
        return Result.success(auditInfoQueryHandler.getById(id));
    }

}
